from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import viewsets
from django_filters import FilterSet,filters
from rest_framework.pagination import  PageNumberPagination
from danwei import models,danwei_serializer

#排序
from rest_framework.filters import OrderingFilter


class My_page(PageNumberPagination):
    page_size_query_param = 'size'

class My_Filter(FilterSet):
    end_time=filters.DateFilter(field_name='end_time',lookup_expr='contains')
    class Meta:
        model=models.Facility
        fields=['name','numbers','cate']

class Cate(viewsets.ModelViewSet):
    queryset = models.Cate.objects.all()
    serializer_class = danwei_serializer.Cate


class Facility(viewsets.ModelViewSet):
    queryset = models.Facility.objects.all()
    serializer_class = danwei_serializer.Facility

    filter_backends = [DjangoFilterBackend,OrderingFilter]
    pagination_class = My_page
    filterset_class=My_Filter
    ordering_fields=['id']

